<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
	<head>
		<base target="_self" />
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <title></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/js/json2.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
		<script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>		
		<script type="text/javascript">
		
		
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							
							toolbar : [
									
									{
										id : listDisplayEId + '_btn_edit',
										text : '入库',
										iconCls : 'icon-edit',
										handler : function() {	
											
											var rows = $('#'+listDisplayEId).datagrid('getSelections');	
											for(var i=0; i<rows.length; i++){
											    var rowIndex=$('#'+listDisplayEId).datagrid('getRowIndex',rows[i]['mid']);
												$('#listDisplay').datagrid('endEdit', rowIndex);
											}
											var row = $('#'+listDisplayEId).datagrid('getSelections');	
											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												var userList = new Array(); 
												var jsonFater;
												for (var i = 0 ; i < row.length;i++){
													
													if ( row[i]['materNum'] == "" || !isNumberAndNoZero(row[i]['materNum'])  ){
														alert("材料"+row[i]['materName']+"，（重量/个/份 ）请填写数字！");
														return false;
													}
													var  jsonSun = "{materId:'"+row[i]['materId']+"',materNum:'"+row[i]['materNum']+"',materLevel:'"+row[i]['materLevel']+"',remarkList:'"+row[i]['remarkList']+"'}";
													userList.push(jsonSun);
												}
												jsonFater = JSON.stringify(userList);
												var str = "json="+jsonFater;	
												document.getElementsByName("materdategridList")[0].value = jsonFater;
												$.messager.confirm('提示', '是否提交记录？', function(r){
													//方法函数 进入后台
													addStore();
													
												});
											}
										}
									}],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						 ,onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
								$('#listDisplay').datagrid('beginEdit', rowIndex);
							} 
						
						});
				
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			
 			function addStore(){
 	 			$('#AddStoreForm').form('submit',
 				{
 					url:'<c:url value='/store/addStore.do'/>', //查询提交路径
 					onSubmit:function()//提交按钮相应函数
 					{
 						return $('#AddStoreForm').form('validate');
 					},
 					success:function(data){
 						data = eval( "("+data+")" );
 		       			if(data.success){
 		       				$.messager.alert("提示", "提交成功！", 'info');
 	       				}else{
 		       				$.messager.alert("提示", data.msg, 'warning');
 	       				}
 		       			$('#'+listDisplayEId).datagrid('reload');
						$('#'+listDisplayEId).datagrid('clearSelections');
 					},
 					error:function(){
 						$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
 						return;
 					}
 				});
 	 			
 			}
 			
 			
 			function searchInfo(){
 				$('#listDisplay').datagrid('load', {
 				materName : $('#materName').val()
 				//,materType : $('#materType').val()
 				});  
 			}
 			$(function() {        
 		          // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
 		          $('#supId').combobox({   
 		                  url:"<c:url value='/store/pulldownSupId.do?space=0'/>",   
 		                  editable:false, //不可编辑状态  
 		                  cache: false,  
 		                  panelHeight: '150',  
 		                  valueField:'supId',     
 		                  textField:'supName',  
 		                  required:true
 		          });      
 		    }); 
		</script>
			</head>
			<body>
			<table width="98%">
			<tr><td>
						<form id="AddStoreForm" name="AddStoreForm" method="post">
			
			<div style="height: auto; width:1180px;background: #fafafa; padding: 2px;" class="easyui-panel" title="&nbsp&nbsp&nbsp&nbsp&nbsp必录信息"  collapsible="true" minimizable="false" maximizable="false" closable="false">
			   <table cellpadding="5">
			      <tr>
                  	<td>供货商</td>
                    <td>
 			            <input class="easyui-combobox" name="supId" id="supId" editable="false" data-options="required:true"/> 
 			        </td>
                  </tr>
                  <tr>
                  	<td>入库备注</td>
                    <td>
 			            <input class="easyui-textbox" name="remark" id="remark" editable="true" data-options="multiline:true,required:true" style="height:60px;width:300px" /> 
 			        </td>
                  </tr>
                  <tr>
                    <td>
				        <input class="easyui-validatebox" type="hidden" name="materdategridList"  />
 			        </td>
                  </tr>
               </table>
             </div>
             </form>
           </td></tr>
           <tr>
			<td>
				<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="查询" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="searchForm" name="searchForm" method="post"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
		            
		                                                           材料名：
							<input type="text" id="materName" name="materName"></input>
		                    <!--                        
		                                                          种类：
							<input type="text" id="materType" name="materType"></input>-->     
		                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		                    <input type="button" onclick="searchInfo()" value="查询">					 
						
						</div>
					</form>
				</div>
		</td>
		</tr>
           </table>
		<table width="98%">
		<tr style="height: 12px;"></tr>
		<tr>
		<td>
				<table id="listDisplay" title="用户列表" 
			iconCls="icon-list" singleSelect="false" idField="mid"
			url="<c:url value="/mater/findSelectMater.do"/>" loadMsg="请稍候......"
			pagination="true" pageSize="20"
			pageList="[10,20,30,40,50,100]" sortName="mid"
			rownumbers="true" sortOrder="asc">
			<thead>
				<tr>
				    <th field="materRole" width="25" align="center"  checkbox="true">
					</th> 
					<th field="mid" width="80" sortable="true" hidden ="true">
						ID
					</th>
				    <th field="materId" width="80" sortable="true" >
						材料ID
					</th>	
 					<th field="materName" width="80"  sortable="true" >
						材料名
					</th>		
					<th field="materType" width="100" formatter="formatFoodType1" sortable="true" >
						种类
					</th>	
					<th field="materLevel" width="100" formatter="formatFoodType" sortable="true" >
						品级
					</th>	
					<th field="materValue" width="100"  sortable="true" align="right">
						价格 (每公斤)
					</th>	
					<th field="materProportion" width="100"  sortable="true" align="right">
						毛料率（%）
					</th>
					<th field="materNum" width="150" sortable="true" editor="text" align="center"  >
						重量（公斤）/个/份
					</th>
					<th field="remarkList" width="150" sortable="true" editor="text" align="center"  >
						备注
					</th>	
 				</tr>
			</thead>
			</table>
			</td>
			</tr>
		</table>
		
	</body>
</html>